define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'csmwj/papercfg/index' + location.search,
                    add_url: 'csmwj/papercfg/add',
                    edit_url: 'csmwj/papercfg/edit',
                    del_url: 'csmwj/papercfg/del',
                    multi_url: 'csmwj/papercfg/multi',
                    import_url: 'csmwj/papercfg/import',
                    table: 'csmwj_paper',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'locales', title: __('Locales'), searchList: {"zh":__('Locales zh'),"en":__('Locales en')}, formatter: Table.api.formatter.normal},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'admin_id', title: __('Admin_id')},
                        {field: 'cfghasdatelimit', title: __('Cfghasdatelimit'), searchList: {"Y":__('Cfghasdatelimit y'),"N":__('Cfghasdatelimit n')}, formatter: Table.api.formatter.normal},
                        {field: 'cfgbegintime', title: __('Cfgbegintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'cfgendtime', title: __('Cfgendtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'cfgmaxanswercount', title: __('Cfgmaxanswercount')},
                        {field: 'cfgresultmsg', title: __('Cfgresultmsg'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'cfgresultmsgimage', title: __('Cfgresultmsgimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'cfghastimelimit', title: __('Cfghastimelimit'), searchList: {"Y":__('Cfghastimelimit y'),"N":__('Cfghastimelimit n')}, formatter: Table.api.formatter.normal},
                        {field: 'cfgtimelimitsecs', title: __('Cfgtimelimitsecs')},
                        {field: 'cfgdisplayscore', title: __('Cfgdisplayscore'), searchList: {"Y":__('Cfgdisplayscore y'),"N":__('Cfgdisplayscore n')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden'),"draft":__('Draft')}, formatter: Table.api.formatter.status},
                        {field: 'themetopnavigationtitle', title: __('Themetopnavigationtitle'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themebannertype', title: __('Themebannertype'), searchList: {"EMPTY":__('Themebannertype empty'),"STRING":__('Themebannertype string'),"IMAGE":__('Themebannertype image'),"IMAGES":__('Themebannertype images')}, formatter: Table.api.formatter.normal},
                        {field: 'themebannerstringstyle', title: __('Themebannerstringstyle'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themebannerstringdivstyle', title: __('Themebannerstringdivstyle'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themebannerimage', title: __('Themebannerimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'themebannerimages', title: __('Themebannerimages'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'themelogoimage', title: __('Themelogoimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'themelogodivstyle', title: __('Themelogodivstyle'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themetitlefont', title: __('Themetitlefont'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themetitledivstyle', title: __('Themetitledivstyle'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themequestionfont', title: __('Themequestionfont'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themequestiondivstyle', title: __('Themequestiondivstyle'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themeoptionsfontcolor', title: __('Themeoptionsfontcolor'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themeoptionsselectedcolor', title: __('Themeoptionsselectedcolor'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themesubmitstring', title: __('Themesubmitstring'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themesubmitdivstyle', title: __('Themesubmitdivstyle'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themewelcomefont', title: __('Themewelcomefont'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themewelcomedivstyle', title: __('Themewelcomedivstyle'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themeendfont', title: __('Themeendfont'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themeendedivstyle', title: __('Themeendedivstyle'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'themetitleshow', title: __('Themetitleshow'), searchList: {"Y":__('Themetitleshow y'),"N":__('Themetitleshow n')}, formatter: Table.api.formatter.normal},
                        {field: 'themequestionnoshow', title: __('Themequestionnoshow'), searchList: {"Y":__('Themequestionnoshow y'),"N":__('Themequestionnoshow n')}, formatter: Table.api.formatter.normal},
                        {field: 'paperimage', title: __('Paperimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
